package com.momo.web.controller.sysSetting;

import com.momo.common.common.JSONResult;
import com.momo.common.req.sysSetting.group.UserGroupReq;
import com.momo.common.req.sysSetting.authority.BatchRoleUserReq;
import com.momo.common.req.sysSetting.authority.RoleReq;
import com.momo.common.res.authority.LoginAuthReq;
import com.momo.service.sysSetting.SysRoleService;
import com.momo.web.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Created by MOMO on 2019/3/22.
 */
@RestController
@RequestMapping(value = "/platform/role", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@Slf4j
public class SysRoleController extends BaseController {
    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/add/v1")
    public JSONResult add(@Validated(RoleReq.Add.class) @RequestBody RoleReq roleReq) {
        return sysRoleService.add(roleReq, redisUser());
    }

    @PostMapping("/modify/v1")
    public JSONResult modify(@Validated(RoleReq.Modify.class) @RequestBody RoleReq roleReq) {
        return sysRoleService.modify(roleReq, redisUser());
    }

    @PostMapping("/status/v1")
    public JSONResult status(@Validated(RoleReq.Status.class) @RequestBody RoleReq roleReq) {
        return sysRoleService.status(roleReq, redisUser());
    }
    @PostMapping("/detail/v1")
    public JSONResult detail(@Validated(RoleReq.Detail.class) @RequestBody RoleReq roleReq) {
        return sysRoleService.detail(roleReq, redisUser());
    }

    @PostMapping("/rolePage/v1")
    public JSONResult rolePage(@RequestBody RoleReq roleReq) {
        return sysRoleService.rolePage(roleReq, redisUser());
    }


    @PostMapping("/rolesToUser/v1")
    public JSONResult rolesToUser(@Validated(BatchRoleUserReq.Status.class) @RequestBody BatchRoleUserReq batchRoleUserReq) {
        return sysRoleService.rolesToUser(batchRoleUserReq, redisUser());
    }

    @PostMapping("/aclsToRole/v1")
    public JSONResult aclsToRole(@Validated(BatchRoleUserReq.Permission.class) @RequestBody BatchRoleUserReq batchRoleUserReq) {
        return sysRoleService.aclsToRole(batchRoleUserReq, redisUser());
    }

    @PostMapping("/roleHaveAclTree/v1")
    public JSONResult roleHaveAclTree(@Validated(LoginAuthReq.Detail.class) @RequestBody LoginAuthReq loginAuthReq) {
        return sysRoleService.roleHaveAclTree(loginAuthReq, redisUser());
    }

    @PostMapping("/vipRoleHaveAclTree/v1")
    public JSONResult vipRoleHaveAclTree(@Validated(UserGroupReq.Detail.class) @RequestBody UserGroupReq userGroupReq) {
        return sysRoleService.vipRoleHaveAclTree(userGroupReq, redisUser());
    }

    @PostMapping("/vipAdminRoleToAcls/v1")
    public JSONResult vipAdminRoleToAcls(@Validated(BatchRoleUserReq.Query.class) @RequestBody BatchRoleUserReq batchRoleUserReq) {
        return sysRoleService.vipAdminRoleToAcls(batchRoleUserReq, redisUser());
    }
    @PostMapping("/userHasRoles/v1")
    public JSONResult userHasRoles(@Validated(BatchRoleUserReq.Status.class) @RequestBody BatchRoleUserReq batchRoleUserReq) {
        return sysRoleService.userHasRoles(batchRoleUserReq, redisUser());
    }

}
